package com.alex.taskmanager.threadpool;

import java.io.InterruptedIOException;

public class WorkerThread extends Thread {

	public boolean stop = false;

	public Worker worker;

	public WorkerThread(Worker worker, String name) {
		super(name);
		this.worker = worker;
	}

	public void stopThread() {
		stop = true;
	}

	@Override
	public void run() {
		worker.onInit();
		while (true) {
			try {
				worker.run();
			} catch (InterruptedException e) {
			} catch (InterruptedIOException e) {
			} catch (Exception e) {
				worker.onError(e);
			}
			if (stop) {
				break;
			}
		}
		worker.onStop();
	}

}
